import { _decorator, EventTouch, Node } from 'cc';
import { LayerType, SoundCode } from '../../Basic/Config/BaseEnum';
import { PanelBase } from '../../Basic/UI/PanelBase';
import { AudioManager } from '../../Basic/Manager/AudioManager';
import { MultiPlatform } from '../../Basic/Model/Platform/MultiPlatform';
import { DataMgr } from '../../Basic/Manager/DataManager';
import { GameParams } from '../../Basic/Config/DataConfig';
import { autoNode } from '../../Basic/Manager/BaseManager';

const { ccclass, property } = _decorator;
@ccclass('SidebarPanel')
export class SidebarPanel extends PanelBase {
  panelLayer: LayerType.TipsLayer = LayerType.TipsLayer;

  clickBackClose: boolean = true;
  blackMask: number = 0.75;

  @autoNode()
  btnIn: Node;

  @autoNode()
  btnGet: Node;

  onReady(): void {
    const state = DataMgr.gameParams.get(GameParams.sidebar);
    this.btnIn.active = state === 0;
    this.btnGet.active = state === 1;
  }

  getAward() {
    DataMgr.changeGameAttr(GameParams.item_box, 1);
    DataMgr.changeGameAttr(GameParams.item_scoop1, 1);
    DataMgr.changeGameAttr(GameParams.item_scoop2, 1);
  }

  onClickBtn(t: EventTouch, data) {
    AudioManager.Singleton.playSound(SoundCode.BTN_CLICK);
    const key = data.toString();
    switch (key) {
      case 'in':
        DataMgr.changeGameAttr(GameParams.sidebar, 1, true);
        this.clickClose();
        MultiPlatform.Ins().platformUnit.navigateToScene();
        break;
      case 'get':
        DataMgr.changeGameAttr(GameParams.sidebar, 2, true);
        this.getAward();
        this.clickClose();
        break;
    }
  }
}
